package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 消息(私信和系统通知)
 * @author CHN
 * @Date
 */
@Getter@Setter
@JsonIgnoreProperties({"handler","json"})//转json时忽略某些属性
public class PrivateMessage extends BaseDomain {
    public static final int STATE_UNREAD=0;//消息未读
    public static final int STATE_READ=1;//消息已读



    //发送者
    private User sender;
    //接收者
    private User receiver;
    //消息内容
    private MessageContent messageContent;
    //发送时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date sendTime;
    //消息状态 0：未读 1：已读 -1：删除
    private Integer brower=STATE_UNREAD;


    //页面状态回显
    public String getBrowerName() {
        String msg="未读";
        if (brower==STATE_READ) {
            msg="已读";
        }
        return msg;
    }


    /**
     * 增加一个属性 json对象
     * @return
     */
    public String getJson() {
        Map<String,Object> map= new HashMap<>();
        map.put("id",id);
        map.put("senderId",sender.id);
        map.put("senderName",sender.getNickName());
        map.put("receiverId",receiver.id);
        map.put("receiverName",receiver.getNickName());
        map.put("content",messageContent.getContent());
        map.put("sendTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(sendTime));
        map.put("brower",brower);
        return JSONUtil.toJSONString(map);
    }
}